/* This source has been formatted by an unregistered SourceFormatX */
/* If you want to remove this info, please register this shareware */
/* Please visit http://www.textrush.com to get more information    */

#include <pronano.h>
#include <tft_lcd.h>
extern const unsigned char gMain_menu_page[][12];
extern const unsigned char g_Msg_page[][12];
char buf2[100];


void LCD_Reset(void);
int main(void)
{
  char key;

  Init_console();
  Init_Interface_IO();

  /*while(1) {
  key = Get_key_queue(0);
  if (key)
  printf("key id: %d\n", key);
  Delay10ms(1);
  }*/
  ProNano_Init();
  //Led_Current_Test();
#ifdef APP_DEBUG
    printf("TFT LCD reset\n");
#endif //APP_DEBUG
  LCD_Reset();


#ifndef DEF_ODM
    Show_logo(1);
#else //DEF_ODM

#if defined LOCCUS_ODM || defined TIANGEN_ODM  || defined KASVI_ODM
      Show_logo(1);
#endif //defined LOCCUS_ODM || defined TIANGEN_ODM  || defined KASVI_ODM
#endif //DEF_ODM
  //#endif


  /*20130425 added by michael
  check if RTC power low battery*/
  if (is_RTC_Low_Power())
  {
    TFT_Send_Command(gMain_menu_page[0], 12, 0); //background
    TFT_Send_Command(g_Msg_page[66], 12, 0); //low battery msg
    Delay100ms(35);
  }

#if 1
  TFT_Send_Command(gMain_menu_page[0], 12, 0); //background
  TFT_Send_Command(g_Msg_page[67], 12, 0);  //lighting initialization
  Setting_up_CC(0, 0, 255);
  Setting_up_CC(1, 0, 255);
  Setting_up_CC(2, 0, 255);
#endif
//#if 0
/*20130515 added by michael
Timer 2 gen one tick every second
screen saving count
*/
  DrvTIMER_Init();
  DrvTIMER_Open(TMR2, 1, PERIODIC_MODE);
  DrvTIMER_SetTimerEvent(TMR2, 10, (TIMER_CALLBACK)TMR_Callback2,0);
  DrvTIMER_EnableInt(TMR2);
#ifdef USE_BSP_ver_June_2011
  DrvTIMER_Start(TMR2);
#endif  //USE_BSP_ver_June_2011

printf("log test: %f\n", log10(100));
  while (1) {
    Display_Main_Menu_Page();
#ifdef APP_DEBUG
    printf("menu_index: %d\n", menu_index);
#endif
//#if 0
    switch (menu_index) {
//Start Measurement
	  case 0:
		  Display_Assay_Page();
/*20130522 added by michael
search the adaptive current configuration code so that the intensity approach to target intensity*/
#if 1
          switch (Assay_index) {
		    case 0:
			    Setting_up_CC(Assay_index, 0, 255);
			    break;
		    case 1:
			    Setting_up_CC(Assay_index, 0, 255);
			    break;
		    case 2:
			    Setting_up_CC(Assay_index, 0, 255);
			    break;
		  }
#endif
		  //ProNano_Measure();
		  Display_Measurement_Page();
		  break;
//Show & Print
	  case 1:
	      Display_Show_And_Print_Page();
		  break;
//Time Setting
	  case 2:
		  if (is_RTC_Low_Power()) {
			  TFT_Send_Command(gMain_menu_page[0], 12, 0);  //background
			  TFT_Send_Command(g_Msg_page[66], 12, 0);  //low battery msg
			  Delay100ms(35);
		  }
		  else
			  //Display_Time_Setup();
			  Time_Setup();
		  break;
//About ProNano
	  case 3:
		  Show_logo(0);
		  break;
    }
//#endif
  }
//#endif  

  while (1)
  {
    key = Get_key_queue(0);
    if (key)
      printf("key id: %d\n", key);
    Delay10ms(1);
  }
  return 0;
}
